package com.example.feign.config;

import com.example.feign.bo.Person01BO;
import com.example.feign.clients.UserClientFeignApi;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * 具体用hytrix/sentinel靠配置文件开关
 */
@Slf4j
@Component
public class UserClientFallbackFactory implements FallbackFactory<UserClientFeignApi> {
    @Override
    public UserClientFeignApi create(Throwable cause) {
        return new UserClientFeignApi() {
            @Override
            public List<Person01BO> select(String id) {
                log.error("select：consumer 端降级了...");
                ArrayList<Person01BO> person01BOS = new ArrayList<>();
                person01BOS.add(new Person01BO());
                return person01BOS;
            }
            @Override
            public String testHystrix() {
                return "testHystrix(provider api)：consumer 端降级了...";
            }

            @Override
            public String testSentinel() {
                return "testSentinel(provider api)：consumer 端降级了...";
            }
        };
    }
}
